package com.example.test;

import in.srain.cube.views.ptr.GridViewWithHeaderAndFooter;

import java.util.HashMap;

import net.duohuo.dhroid.activity.BaseActivity;
import net.duohuo.dhroid.adapter.NetBeanAdapter;
import net.duohuo.dhroid.net.model.JSONObjectN;

import org.json.JSONException;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.example.test.api.API;
import com.example.test.views.RefreshGridViewAndMore;

public class GridViewActivity extends BaseActivity {

	RefreshGridViewAndMore gridV;

	GridViewWithHeaderAndFooter contentGridV;

	NetBeanAdapter<HashMap<String, Object>> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gridview);
		gridV = (RefreshGridViewAndMore) findViewById(R.id.my_gridview);
		contentGridV = gridV.getContentView();
		contentGridV.setNumColumns(2);
		initAdapter();
	}

	private void initAdapter() {
		adapter = new NetBeanAdapter<HashMap<String, Object>>(
				new API().marketGoodList, GridViewActivity.this,
				R.layout.item_list);
		adapter.fromWhat("list");
		adapter.addparam("user_id", "7");
		adapter.addparam("communityid", "1");
		adapter.addparam("catid", "37");
		adapter.addField("title", R.id.name);
		gridV.setAdapter(adapter);
		contentGridV.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				JSONObjectN jo = adapter.getTItem(position);
				HashMap<String, Object> map = adapter.getTItem(position);
				try {
					System.out.println("数据........." + jo.getString("price"));
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		});
	}

}
